Repository navigation
Keep file I/O out of DefaultStorageFactory for trimmed builds - #47
Merged
Merged
Conversation
DefaultStorageFactory is rooted by every use of DatabaseLoadOptions, and its FileStream branch statically referenced PreadPageLoader, whose pread path (RandomAccess over SafeFileHandle) drags native file I/O symbols such as SystemNative_PReadV into every trimmed or AOT-compiled application — including ones that only ever read from a MemoryStream. Environments without those symbols (e.g. godot-dn2cpp wasm exports) could not link DryDB at all. Move the FileStream handling into a public FileStorage.Factory that OpenFileAsync swaps in when the options still carry the default factory, so file support is rooted only by callers that actually open files. A memory-only app trimmed with TrimMode=full now carries no PreadPageLoader, RandomAccess, or SystemNative_PReadV references. BREAKING: OpenAsync(fileStream) no longer picks PreadPageLoader implicitly; it throws NotSupportedException with guidance to use OpenFileAsync or set DatabaseLoadOptions.StorageFactory = FileStorage.Factory. Fixes #45 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #45
Problem
DatabaseLoadOptions.DefaultStorageFactoryis rooted by every use ofDatabaseLoadOptions, and itsFileStreambranch statically referencedPreadPageLoader. Its pread path (RandomAccessoverSafeFileHandle) drags native file I/O symbols such asSystemNative_PReadVinto every trimmed/AOT-compiled application, even ones that only read from aMemoryStream. Environments without those symbols (the reported godot-dn2cpp wasm export) cannot link DryDB at all; for everyone else it is dead weight in trimmed builds.Fix
Move the
FileStreamhandling into a publicFileStorage.Factory(inDryDB.Storages), which handlesFileStreamand falls back toDefaultStorageFactoryfor everything else.OpenFileAsyncswaps it in when the options still carry the default factory (a customStorageFactorykeeps winning), so file support is rooted only by callers that actually open files — essentially the shape proposed in the issue.Breaking change
OpenAsync(fileStream)no longer picksPreadPageLoaderimplicitly. It throwsNotSupportedExceptionwhose message points to the two replacements:ReadOnlyDatabase.OpenFileAsync(path), ornew DatabaseLoadOptions { StorageFactory = FileStorage.Factory }when you need to pass an already openedFileStream.Verification
OpenAsync(MemoryStream),OpenFileAsync(default and with a customStorageFactory, which is still honored),OpenAsync(FileStream)→ guidedNotSupportedException, andOpenAsync(FileStream)withFileStorage.Factory→ works.TrimMode=fullruns correctly and itsDryDB.dllcontains noPreadPageLoader,FileStorage,RandomAccess, orOpenFileAsyncreferences (control symbolsDatabaseBuilder/InMemoryPageLoaderremain).dotnet test: 95/95 passing.🤖 Generated with Claude Code